#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXN    128

int comlen(char *p, char *q)
{
    int i = 0;
    while (*p && p[i] == q[i])
        i ++;

    return i;
}

int pstrcmp(const void *p, const void *q)
{
    return strcmp(*(char **)p, *(char **)q);
}

void find_longest_same_string(char *str)
{
    char *a[MAXN], same[MAXN];
    int i, j, len, maxlen, max;

    i = 0;
    while (*str != '\0')
        a[i++] = str++;
  
    qsort(a, i, sizeof(char *), pstrcmp);

    maxlen = 0;
    for (j = 0; j < i-1; j++) {
        if ((len = comlen(a[j], a[j+1])) > maxlen) {
            maxlen = len;
            max = j;
        }
    }

    if (maxlen == 0) {
        printf("no same string\n");
        return ;
    }

    memcpy(same, a[max], maxlen);
    same[maxlen] = '\0';
    
    printf("longest_same_string is %s\n", same);
}

int main(int argc, char *argv[])
{
    char s[MAXN];

    while (fgets(s, MAXN, stdin) != NULL) {
        s[strlen(s)-1] = '\0';
        find_longest_same_string(s);        
    }

    return 0;
}
